package com.artist.controller;

import com.artist.entity.TbMessage;
import com.artist.service.MsgService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;
import java.util.List;

@Api(tags = "留言管理")
@Controller
public class MsgController {
    @Autowired
    private MsgService msgservice;
    @ApiOperation(value = "留言列表")
    @GetMapping("/msg")
    @ResponseBody
    public List<TbMessage> allMsg(){
        //分页 pageNum：当前页     pageSize页大小
        PageHelper.startPage(2, 2);
        List<TbMessage> list= msgservice.allMessage();
        //分页信息对象
        PageInfo pageInfo = new PageInfo<TbMessage>(list);
        System.out.println("总记录熟："+pageInfo.getTotal());
        System.out.println("总页数："+pageInfo.getPages());
        System.out.println("单前页号："+pageInfo.getPageNum());
        System.out.println("页大小："+pageInfo.getPageSize());
        return list;
    }
    @ApiOperation(value ="查询留言")
    @GetMapping("/msg/{mid}")
    public String getMsg(@PathVariable Long mid){
        TbMessage tbMessage= msgservice.selectMessageById(mid);
        return "getmsg";
    }
    @ApiOperation(value = "回复留言")
    @PutMapping("/msg/{mid}")
    public String updateMsg(@RequestBody String msg){
        TbMessage tbMessage = new TbMessage();
        tbMessage.setMMsg(msg);
        tbMessage.setMUpdateAt((Timestamp) new java.util.Date());
        tbMessage.setUId(3L);
        msgservice.updateMessage(tbMessage);
        return "msglist";
    }
    @ApiOperation(value = "删除留言")
    @DeleteMapping("/msg/{mid}")
    public String deleteMsg(@PathVariable Long mid){
        return "msglist";
    }
}
